HTML:
CSS:
JS:
PHP:
public function mbUploadImg(){ $upload = new Upload(); // 实例化上传类 $upload->maxSize = 5242880 ; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Public/'; // 上传文件 $info = $upload->uploadOne($_FILES['files']); if($info) { // 上传成功 $data['name'] = $info['name']; $data['ext'] = $info['ext']; $data['type'] = $info['type']; $data['savename'] = $info['savename']; $data['savepath'] = "/Public/".$info['savepath'].$info['savename']; $imgId = M('upload_img')->add($data); if($imgId){ $resData['code'] = 200; $resData['msg'] = '成功'; $resData['id'] = $imgId; $resData['name'] = $data['name']; $resData['savepath'] = $data['savepath']; echo json_encode($resData); return; } } // 上传错误提示错误信息 return $this->ajaxReturn(['code'=>400,'msg'=>$upload->getError()]);}